package com.delistry.database.schema;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.delistry.database.DatabaseFactory;
import com.delistry.server.utils.SQLUtil;

public class AccountDelistyTable {

	private static AccountDelistyTable _instance;

	public static AccountDelistyTable getInstance() {
		if (_instance == null) {
			_instance = new AccountDelistyTable();
		}
		return _instance;
	}

	public static final String TableName = "account_delisty";

	public AccountDelistyTable() {
		// Scan Schema
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DatabaseMetaData meta;
		try {

			conn = DatabaseFactory.getInstance().getConnection();			
			meta = conn.getMetaData();
			rs = meta.getColumns(null, null, TableName, null);

			while (rs.next()) {

				System.out.println(rs.getString("COLUMN_NAME"));
				String columnName = rs.getString("COLUMN_NAME");
				System.out.println("column name=" + columnName);
				String columnType = rs.getString("TYPE_NAME");
				System.out.println("type:" + columnType);
				int size = rs.getInt("COLUMN_SIZE");
				System.out.println("size:" + size);
				int nullable = rs.getInt("NULLABLE");
				if (nullable == DatabaseMetaData.columnNullable) {
					System.out.println("nullable true");
				} else {
					System.out.println("nullable false");
				}
				int position = rs.getInt("ORDINAL_POSITION");
				System.out.println("position:" + position);

			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			SQLUtil.close(conn);
			SQLUtil.close(rs);
		}

	}

}
